/*
 * @Author: qin
 * @Date:   2018-08-28
 * +----------------------------------------------------------------------
 * | admin [ 后台管理系统公共配置信息 ]
 * | 报审材料详情模板
 * +----------------------------------------------------------------------
 */
layui.define(['bluebird', 'templateInit', 'jquery', 'element', 'form', 'layerPop', 'configure', 'configureCom', 'apply'], function (exports) {
    var templateInit = layui.templateInit;
    var $ = layui.$;
    var templateHtml = $('#templateId').html();
    var element = layui.element;
    var form = layui.form;
    var layerPop = layui.layerPop;
    var configure = layui.configure;
    var configureCom = layui.configureCom;
    var apply = layui.apply;

    var reportMateriaDetail = {
        data: {
            singleProjectId: configureCom.GetQueryString('singleProjectId') || '',//单位工程ID
            auditItemCheckIndex: 0,//当前选中的审查项下标
            auditItemList: [
                {
                    auditItemCode: '1010',
                    auditItemName: '住建审查',
                    auditItemStatus: '',
                    auditItemChecked: true,
                    auditItemOrganName: '',//审图机构名称
                    auditItemOrganId: '',//审图机构ID
                    auditItemMaterials: [

                    ]
                },
                {
                    auditItemCode: '1020',
                    auditItemName: '消防审查',
                    auditItemStatus: '',
                    auditItemChecked: false,
                    auditItemOrganName: '',//审图机构名称
                    auditItemOrganId: '',//审图机构ID
                    auditItemMaterials: [

                    ]
                },
                {
                    auditItemCode: '1030',
                    auditItemName: '人防审查',
                    auditItemStatus: '',
                    auditItemChecked: false,
                    auditItemOrganName: '',//审图机构名称
                    auditItemOrganId: '',//审图机构ID
                    auditItemMaterials: [

                    ]
                }]
        },
        render: function () {
            //数据准备
            apply.param.data.singleProjectId = reportMateriaDetail.data.singleProjectId;
            apply.refusedApplyDetail().then(function (res) {
                $(res.result).each(function (index, item) {
                    $(reportMateriaDetail.data.auditItemList).each(function (index1, item1) {
                        if (item1.auditItemCode === item.acceptType) {
                            //匹配则赋值
                            item1.auditItemChecked = true;
                            item1.selectOrganId = item.applyOrganization.id;
                            item1.selectOrganName = item.applyOrganization.name;
                        }
                    });
                });
                //选择选中的的第一项作为当前选中项
                for (var i = reportMateriaDetail.data.auditItemList.length - 1; i >= 0; i--) {
                    if (reportMateriaDetail.data.auditItemList[i].auditItemChecked) {
                        reportMateriaDetail.data.auditItemCheckIndex = i;
                    }
                }
                templateInit.init('view', reportMateriaDetail.data, templateHtml);
                element.render('collapse');
                element.render('tab');
                form.render();
            });
        },
        eventBind: function () {
        }
    };

    exports('reportMateriaDetail', reportMateriaDetail);
});